import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

import {postbkImage,
    postChangeSignature,
    postChangePersonalMessage,
    postSendHeaderImage,
    postSendPassword,
    postChangePassword,
    postYI,
    postInsertPic,
    postOtherSource,
    postImageSource,
    postTwoSource,
    getTwoSource,
    postUseDefaultImg,
    getStart,
    deleteStart,
    getDetailWrite,
    deleteDetailWrite,
    getDetailEdit,
    postSaveOtherSource,
    postSaveImageSource
} from '@/api'

const state = {}

const actions = {
    //修改背景图
   async reqSendbkimage(context,formDate){
        let result = await postbkImage(formDate);
        return new Promise((res,rej)=>{
            res(result)
        })
   },
   //通过input直接修改签名
   async reqChangeSignature(context,value){
        let result = await postChangeSignature(value);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //个人中心资料修改
    async reqChangePersonalMessage(context,obj){
        let result = await postChangePersonalMessage(obj);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //头像上传
    async reqSendHeaderImage(context,formData){
        let result = await postSendHeaderImage(formData);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //密码校验
    async reqSendPassword(context,password){
        let result = await postSendPassword(password);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //修改密码
    async reqChangePassword(context,password){
        let result = await postChangePassword(password);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //提交YI
    async reqYI(context,str){
        let result = await postYI(str);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //插入富文本文章图片
    async reqInsertPic(context,formData){
        let result = await postInsertPic(formData);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //写文章其他参数发送
    async reqOtherSource(context,obj){
        let result = await postOtherSource(obj);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //头图发送
    async reqImageSource(context,val){
        let {formData,article_id} = val
        let result = await postImageSource(formData,article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //默认发送
    async reqUseDefaultImg(context,val){
        let {article_id} = val
        let result = await postUseDefaultImg(article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //two_source 发送
    async reqTwoSource(context,str){
        let result = await postTwoSource(str);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //two_source 获取
    async reqGetTwoSource(context){
        let result = await getTwoSource();
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //用户收藏
    async reqGetStart(context,page){
        let result = await getStart(page);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    // 取消收藏
    async reqDeleteStart(context,article_id){
        let result = await deleteStart(article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //获取写的文章
    async reqDetailWrite(context,page){
        let result = await getDetailWrite(page);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //删除文章
    async reqDeleteDetail(context,article_id){
        let result = await deleteDetailWrite(article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //获取文章所有资料
    async reqGetDetailEdit(context,article_id){
        let result = await getDetailEdit(article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    // 编辑文章保存的其他资源
    async reqSaveOtherSource(context,obj){
        let result = await postSaveOtherSource(obj);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    //更改图片
    async reqSaveImageSource(context,val){
        let {formData,article_id} = val
        let result = await postSaveImageSource(formData,article_id);
        return new Promise((res,rej)=>{
            res(result)
        })
    },
    
}

const mutations = {}

const getters = {}

export default {
    namespaced:true,state,mutations,actions,getters
}